#pragma once

#include <QWidget>
#include <QPoint>
#include <QSize>
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
#include <QPixmap>
#include <QPainter>
#include <QPainterPath>
#include <QRect>
#include <QMouseEvent>

enum ButtonType {
	MIN_BUTTON=0,
	MIN_MAX_BUTTON,
	ONLY_CLOSE_BUTTON
};

class TitleBar  : public QWidget
{
	Q_OBJECT

public:
	TitleBar(QWidget *parent = nullptr);
	~TitleBar();

	void setTitleIcon(const QString &fikePath);
	void setTitleContent(const QString &titleContent);
	void setTitleWidth(int width);
	void setButtonType(ButtonType bottonType);

	void saveRestoreInfo(const QPoint &point, const QSize &size);
	void getRestoreInfo(QPoint &point, QSize &size);

protected:
	virtual void paintEvent(QPaintEvent *event)override;
	virtual void mousePressEvent(QMouseEvent *event)override;
	virtual void mouseReleaseEvent(QMouseEvent *event)override;
	virtual void mouseDoubleClickEvent(QMouseEvent *event)override;
	virtual void mouseMoveEvent(QMouseEvent *event)override;

private:
	void initControl();			//初始化控件
	void initConnections();		//初始化信号与槽的连接
	void loadStyleSheet(const QString &sheetName);		//加载样式表

signals:
	//按钮发送signal
	void signalButtonMinClicked();
	void signalButtonRestoreClicked();
	void signalButtonMaxClicked();
	void signalButtonCloseClicked();
		//signalButtonCloseClicked

private slots:
	//按钮响应slot
	void onButtonMinClicked();
	void onButtonRestoreClicked();
	void onButtonMaxClicked();
	void onButtonCloseClicked();

private:
	QLabel *m_pTitleIcon;
	QLabel *m_pTitleContent;
	QPushButton *m_pButtonMin;
	QPushButton *m_pButtonMax;
	QPushButton *m_pButtonClose;
	QPushButton *m_pButtonRestore;

	//最大化还原按钮变量(用于保存窗体位置及大小)
	QPoint m_restorePos;
	QSize m_restoreSize;

	//移动窗口变量
	bool m_isPressed;
	QPoint m_startMovePos;

	QString m_titleContent;
	ButtonType m_buttonType;
	
};
